package edu.hawaii.examschd.modules.CouchDB;

import static org.junit.Assert.*;
import org.junit.Test;

public class TestCouchDB {

  CouchDB testClient;
  String host = "127.0.0.1";
  int port = 5984;
  int crn = 81455;
  String url_crn = "/uhm/_design/uhm/_view/crn?key=\"";
  String url_exam = "/uhm/_design/uhm/_view/exam?key=\"";
  String error;
  String line;

  // 84850 ["ICS", "141", "TR", "1330", "1445"]
  // 81455 ["ICS", "690", "R", "1630", "1730"]
  // 85833 ["JPN", "401", "MTWF", "1030", "1120"]
  // 87748 ["JPN", "425", "MWF", "0930", "1020"]

  public TestCouchDB() {
    testClient = new CouchDB();
  }

  @Test
  public void testGet_class_name() {
    line = testClient.get_class_name(81455);
    error = "testGetClassName failed: incorrect class name returned";
    assertTrue(error, line.contains("ICS 690"));
    line = testClient.get_class_name(84850);
    assertTrue(error, line.contains("ICS 141"));
    line = testClient.get_class_name(85833);
    assertTrue(error, line.contains("JPN 401"));
    line = testClient.get_class_name(87748);
    assertTrue(error, line.contains("JPN 425"));
  }

  @Test
  public void testGet_class_by_crn_as_str() {
    error = "testGet_class_by_crn_as_str failed: return does not match expected values";
    line = testClient.get_class_by_crn_as_str(81455);
    assertEquals(line, "ICS,690,R,1630,1730");
    line = testClient.get_class_by_crn_as_str(84850);
    assertEquals(line, "ICS,141,TR,1330,1445");
    line = testClient.get_class_by_crn_as_str(85833);
    assertEquals(line, "JPN,401,MTWF,1030,1120");
  }
}